import request from "@/utils/request"
const BASE_URL = process.env.VUE_APP_BASE_URL_CRM
/**
 * 新建商机
 * @param {*} data
 */
export function crmBusinessSaveAPI(data) {
	const url = data.entity && data.entity.businessId ? "update" : "add"
	return request({
		url: BASE_URL + `crmBusiness/${url}`,
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 列表
 * @param {*} data
 */
export function crmBusinessIndexAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/queryPageList",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 删除
 * @param {*} data
 */
export function crmBusinessDeleteAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/deleteByIds",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 商机状态组
 * @param {*} data
 */
export function crmBusinessStatusListAPI(data) {
	return request({
		url: BASE_URL + "crmFlow/queryBusinessSetting",
		method: "post",
		data: data
	})
}
// export function crmBusinessStatusListAPI(data) {
//   return request({
//     url: BASE_URL +  'crmBusiness/queryBusinessStatusOptions',
//     method: 'post',
//     data: data
//   })
// }

/**
 * 商机下的状态组
 * @param {*} data
 */
export function crmBusinessStatusByIdAPI(data) {
	return request({
		url: BASE_URL + `crmBusiness/queryBusinessStatus/${data.businessId}`,
		method: "post",
		data: data
	})
}

/**
 * 详情
 * @param {*} data
 */
export function crmBusinessReadAPI(data) {
	return request({
		url: BASE_URL + `crmBusiness/queryById/${data.businessId}`,
		method: "post"
	})
}

/**
 * 商机转移
 * @param {*} data
 */
export function crmBusinessTransferAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/changeOwnerUser",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 商机转移
 * @param {*} data
 */
export function crmBusinessAdvanceAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/boostBusinessStatus",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 商机相关产品
 * @param {*} data
 */
export function crmBusinessProductAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/queryProduct",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 合同
 * @param {*} data
 */
export function crmBusinessQueryContractAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/queryContract",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

// 团队操作
/**
 * 团队成员创建
 * @param {*} data
 */
export function crmBusinessSettingTeamSaveAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/addMembers",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

export function crmBusinessSettingTeamDeleteAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/deleteMembers",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

export function crmBusinessTeamMembersAPI(data) {
	return request({
		url: BASE_URL + `crmBusiness/getMembers/${data.id}`,
		method: "post"
	})
}

export function crmBusinessUpdateMembersAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/updateMembers",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 退出团队
 * @param {*} data
 */
export function crmBusinessExitTeamAPI(data) {
	return request({
		url: BASE_URL + `crmBusiness/exitTeam/${data.id}`,
		method: "post"
	})
}

/**
 * 商机关联联系人
 * @param {*} data
 */
export function crmBusinessRelateContactsAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/relateContacts",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 商机取消关联联系人
 * @param {*} data
 */
export function crmBusinessUnrelateContactsAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/unrelateContacts",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 商机下联系人
 * @param {*} data
 */
export function crmBusinessQueryContactsAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/queryContacts",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 设置首要联系人
 * @param {*} data
 *
 */
export function crmBusinessSetContactsAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/setContacts",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 附件列表
 * @param {*} data
 *
 */
export function crmBusinessFileListAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/queryFileList",
		method: "post",
		data: data
	})
}

/**
 * tab数量
 * @param {*} data
 *
 */
export function crmBusinessNumAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/num",
		method: "post",
		data: data
	})
}

/**
 * 商机导出
 * @param {*} data
 */
export function crmBusinessExcelExportAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/batchExportExcel",
		method: "post",
		data: data,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		},
		responseType: "blob",
		timeout: 60000
	})
}

export function crmBusinessExcelAllExportAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/allExportExcel",
		method: "post",
		data: data,
		responseType: "blob",
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 新增团队成员交叉产品信息
 */
export function crmBusinessAddOrUpdateTeamProductAPI(data) {
	return request({
		url: BASE_URL + `crmBusiness/addOrUpdateTeamProduct/${data.id}`,
		method: "post",
		data: data.entity,
		headers: {
			"Content-Type": "application/json;charset=UTF-8"
		}
	})
}

/**
 * 删除团队成员交叉产品信息
 */
export function crmBusinessDeleteTeamProductAPI(id) {
	return request({
		url: BASE_URL + `crmBusiness/deleteTeamProductUser/${id}`,
		method: "post"
	})
}

/**
 * 查询团队成员交叉产品信息
 */
export function crmBusinessQueryTeamProductAPI(id) {
	return request({
		url: BASE_URL + `crmBusiness/queryTeamProductList/${id}`,
		method: "post"
	})
}

/**
 * 导入
 * @param {*} data
 *
 */
export function crmBusinessExcelImportAPI(data) {
	var param = new FormData()
	Object.keys(data).forEach(key => {
		param.append(key, data[key])
	})
	return request({
		url: BASE_URL + "crmBusiness/uploadExcel",
		method: "post",
		data: param,
		headers: {
			"Content-Type": "multipart/form-data"
		}
	})
}

/**
 * 导入模板下载
 * @param {*} data
 *
 */
export const crmBusinessExcelDownloadURL =
	process.env.VUE_APP_BASE_API + "crmBusiness/downloadExcel"
export function crmBusinessDownloadExcelAPI(data) {
	return request({
		url: BASE_URL + "crmBusiness/downloadExcel",
		method: "post",
		data: data,
		responseType: "blob"
	})
}
